home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / mint / netlib / include / if.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-27  |  5.7 KB  |  191 lines

  1. #ifndef _IF_H
  2. #define _IF_H
  3.  
  4. #include "socket.h"
  5. #include "buf.h"
  6.  
  7. /* net interface flags */
  8. #define IFF_UP        0x0001        /* if is up */
  9. #define IFF_BROADCAST    0x0002        /* if supports broadcasting */
  10. #define IFF_DEBUG    0x0004        /* if debugging is on */
  11. #define IFF_LOOPBACK    0x0008        /* if is software loopback */
  12. #define IFF_POINTOPOINT    0x0010        /* if for p2p connection */
  13. #define IFF_NOTRAILERS    0x0020        /* if should not use trailer encaps. */
  14. #define IFF_RUNNING    0x0040        /* if ressources are allocated */
  15. #define IFF_NOARP    0x0080        /* if should not use arp */
  16. #define IFF_MASK    (IFF_UP|IFF_DEBUG|IFF_NOTRAILERS|IFF_NOARP)
  17.  
  18. #define IF_NAMSIZ        16    /* maximum if name len */
  19. #define IF_MAXQ            60    /* maximum if queue len */
  20. #define IF_SLOWTIMEOUT        1000    /* one second */
  21. #define IF_PRIORITY_BITS    1
  22. #define IF_PRIORITIES        (1 << IF_PRIORITY_BITS)
  23.  
  24. /*
  25.  * socket address carrying a hardware address
  26.  */
  27. struct sockaddr_hw {
  28.     unsigned short    shw_family;
  29.     unsigned short    shw_type;
  30.     unsigned short    shw_len;
  31.     unsigned char    shw_addr[8];
  32. };
  33.  
  34. struct netif;
  35.  
  36. /* structure for holding address information, assumes internet style */
  37. struct ifaddr {
  38.     struct sockaddr    addr;        /* local address */
  39.     union {
  40.         struct sockaddr    broadaddr;    /* broadcast address */
  41.         struct sockaddr    dstaddr;    /* point2point dst address */
  42.     } ifu;
  43.     struct netif    *ifp;        /* interface this belongs to */
  44.     struct ifaddr    *next;        /* next ifaddr */
  45.     short        family;        /* address family */
  46.     unsigned short    flags;        /* flags */
  47.  
  48. /* AF_INET specific */
  49.     unsigned long    net;        /* network id */
  50.     unsigned long    netmask;    /* network mask */
  51.     unsigned long    subnet;        /* subnet id */
  52.     unsigned long    subnetmask;    /* subnet mask */
  53.     unsigned long    net_broadaddr;    /* logical broadcast addr */
  54. };
  55.  
  56. /* Interface packet queue */
  57. struct ifq {
  58.     short    maxqlen;
  59.     short    qlen;
  60.     short    curr;
  61.     BUF    *qfirst[IF_PRIORITIES];
  62.     BUF    *qlast[IF_PRIORITIES];
  63. };
  64.  
  65. /* Hardware address */
  66. struct hwaddr {
  67.     short        len;
  68.     unsigned char    addr[10];
  69. };
  70.  
  71. /* structure describing a net interface */
  72. struct netif {
  73.     char        name[IF_NAMSIZ];/* interface name */
  74.     short        unit;        /* interface unit */
  75.  
  76.     unsigned short    flags;        /* interface flags */
  77.     unsigned long    metric;        /* routing metric */
  78.     unsigned long    mtu;        /* maximum transmission unit */
  79.     unsigned long    timer;        /* timeout delta in ms */
  80.     short        hwtype;        /* hardware type */
  81. /*
  82.  * These must match the ARP hardware types in arp.h
  83.  */
  84. #define HWTYPE_NONE    200        /* for SLIP, PLIP, loop etc. */
  85. #define HWTYPE_ETH    1        /* ethernet */
  86.  
  87.     struct hwaddr    hwlocal;    /* local hardware address */
  88.     struct hwaddr    hwbrcst;    /* broadcast hardware address */
  89.  
  90.     struct ifaddr    *addrlist;    /* addresses for this interf. */
  91.     struct ifq    snd;        /* send and recv queue */
  92.     struct ifq    rcv;
  93.  
  94.     long        (*open) (struct netif *);
  95.     long        (*close) (struct netif *);
  96.     long        (*output) (struct netif *, BUF *, char *, short, short);
  97.     long        (*ioctl) (struct netif *, short, long);
  98.     void        (*timeout) (struct netif *);
  99.  
  100.     void        *data;        /* extra data the if may want */
  101.  
  102.     unsigned long    in_packets;    /* # input packets */
  103.     unsigned long    in_errors;    /* # input errors */
  104.     unsigned long    out_packets;    /* # output packets */
  105.     unsigned long    out_errors;    /* # output errors */
  106.     unsigned long    collisions;    /* # collisions */
  107.  
  108.     struct netif    *next;        /* next interface */
  109.  
  110.     short        maxpackets;    /* max. number of packets the harware
  111.                      * can receive in fast succession.
  112.                      * 0 means unlimited. (this is used
  113.                      * for ethercards with few receive
  114.                      * buffers and slow io to don't over-
  115.                      * flow them with packets.
  116.                      */
  117.     long        reserved[5];
  118. };
  119.  
  120. /* interface statistics */
  121. struct ifstat {
  122.     unsigned long    in_packets;    /* # input packets */
  123.     unsigned long    in_errors;    /* # input errors */
  124.     unsigned long    out_packets;    /* # output packets */
  125.     unsigned long    out_errors;    /* # output errors */
  126.     unsigned long    collisions;    /* # collisions */
  127. };
  128.  
  129. /* argument structure for the SIOC* ioctl()'s on sockets */
  130. struct ifreq {
  131.     char    ifr_name[IF_NAMSIZ];        /* interface name */
  132.     union {
  133.         struct    sockaddr addr;        /* local address */
  134.         struct    sockaddr dstaddr;    /* p2p dst address */
  135.         struct    sockaddr broadaddr;    /* broadcast addr */
  136.         struct    sockaddr netmask;    /* network mask */
  137.         short    flags;            /* if flags, IFF_* */
  138.         long    metric;            /* routing metric */
  139.         long    mtu;            /* max transm. unit */
  140.         struct    ifstat stats;        /* interface statistics */
  141.         void    *data;            /* other data */
  142.     } ifru;
  143. };
  144.  
  145. /* result structure for the SIOCGIFCONF socket ioctl() */
  146. struct ifconf {
  147.     short    len;                /* buffer len */
  148.     union {
  149.         void         *buf;        /* the actual buffer */
  150.         struct ifreq     *req;        /* ifreq structure */
  151.     } ifcu;
  152. };
  153.  
  154. #ifndef NOEXTERNS
  155. extern struct netif    *allinterfaces;
  156.  
  157. extern short        if_enqueue    (struct ifq *, BUF *, short pri);
  158. extern BUF        *if_dequeue    (struct ifq *);
  159. extern void        if_flushq    (struct ifq *);
  160. extern long        if_register    (struct netif *);
  161. extern long        if_init        (void);
  162. extern short        if_input    (struct netif *, BUF *, long, short);
  163. #endif
  164.  
  165. /*
  166.  * These must match ethernet protcol types
  167.  */
  168. #define PKTYPE_IP    0x0800
  169. #define PKTYPE_ARP    0x0806
  170. #define PKTYPE_RARP    0x8035
  171.  
  172. #ifndef NOEXTERNS
  173. extern long        if_ioctl    (short cmd, long arg);
  174. extern long        if_config    (struct ifconf *);
  175.  
  176. extern struct netif    *if_name2if    (char *);
  177. extern struct netif    *if_net2if    (unsigned long);
  178. extern long        if_setifaddr    (struct netif *, struct sockaddr *);
  179. extern struct ifaddr    *if_af2ifaddr    (struct netif *, short fam);
  180. extern short        if_getfreeunit    (char *);
  181.  
  182. extern long        if_open        (struct netif *);
  183. extern long        if_close    (struct netif *);
  184. extern long        if_send        (struct netif *, BUF *, unsigned long, short);
  185. extern void        if_load        (void);
  186.  
  187. extern struct netif    *allinterfaces, *if_lo, *if_primary;
  188. #endif
  189.  
  190. #endif /* _IF_H */
  191.